package cn.com.cetccst.devicerestriction.ui;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;

import cn.com.cetccst.datacenter.policy.entity.RestrictionEntity;
import cn.com.cetccst.devicerestriction.R;
import cn.com.cetccst.devicerestriction.RestrictionModel;
import cn.com.cetccst.devicerestriction.databinding.AdapterDeviceRestrictionBinding;
import cn.com.cetccst.uicomponents.binding.recyclerview.SimpleDataBindingAdapter;

public class DeviceRestrictionAdapter extends SimpleDataBindingAdapter<RestrictionEntity, AdapterDeviceRestrictionBinding> {
    public DeviceRestrictionAdapter(Context context) {
        super(context, R.layout.adapter_device_restriction, new DiffUtil.ItemCallback<RestrictionEntity>() {
            @Override
            public boolean areItemsTheSame(@NonNull RestrictionEntity oldItem, @NonNull RestrictionEntity newItem) {
                return oldItem.getId() == newItem.getId();
            }

            @Override
            public boolean areContentsTheSame(@NonNull RestrictionEntity oldItem, @NonNull RestrictionEntity newItem) {
                return oldItem.getId() == newItem.getId();
            }
        });
    }

    @Override
    protected void onBindItem(AdapterDeviceRestrictionBinding binding, RestrictionEntity item, RecyclerView.ViewHolder holder) {
        binding.setEntity(item);
    }

    @BindingAdapter("type")
    public static void bindType(ImageView view, String type) {
        view.setImageResource(RestrictionModel.lookUp(type).drawableId);
    }
}
